package com.sh.util;

import java.util.Properties;

import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttPersistenceException;
import org.eclipse.paho.client.mqttv3.MqttTopic;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
* @comments
* @author  zg
* @date 2018年4月5日
*/
@Component
@PropertySource("classpath:conf.properties")
@ConfigurationProperties(prefix="mqtt")
public class MqttUtils {
	
	private String host;
	
	private String userName;
	
	private String passWord;
	
	private String clientId;
	
	
	public void publish(MqttTopic topic, MqttMessage message) throws MqttPersistenceException, MqttException {
		MqttDeliveryToken token = topic.publish(message);
		token.waitForCompletion();
		System.out.println("message is published completely! " + token.isComplete());
	}
	
	
	
	//--------------  getter and setter --------------------------------------
	public String getHost() {
		return host;
	}

	public String getUserName() {
		return userName;
	}

	public String getPassWord() {
		return passWord;
	}

	public String getClientId() {
		return clientId;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

	public void setClientId(String clientId) {
		this.clientId = clientId;
	}
	
}
